package com.example.academic_affairs_system.config;

import com.example.academic_affairs_system.common.UserAuthorizationInfo;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 缓存配置
 * @author hjx
 * @since 2023/02/01 1:28 PM
 **/
@Configuration
public class CacheConfig {
    /**
     * 用户令牌缓存
     *
     * <p>key 值是{@link UserAuthorizationInfo} 用户令牌信息，value 是有效时间
     *
     * @return {@link Cache}
     */
    @Bean("userAuthorizationCache")
    public Cache<UserAuthorizationInfo, Long> userAuthorizationCache() {
        return Caffeine.newBuilder().initialCapacity(100).maximumSize(1000).build();
    }
}
